<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 6/20/24
 * Time: 1:51 PM
 */

namespace App\Http\Controllers\Admin;

use App\Services\TitleService;
use Illuminate\Http\Request;
use App\Http\Controllers\ResourceController;

class TitleController extends ResourceController
{
    protected $service;

    public function __construct(TitleService $service)
    {
        $this->service = $service;
    }


    /**
     * 获取分类列表
     *
     * @param Request $request
     * @return mixed
     */
    public function getList(Request $request)
    {
        return $this->responseWithSuccess($this->service->getList($request->post()));
    }


    /**
     * 获取所有分类
     *
     * @return mixed
     */
    public function getAll()
    {
        return $this->responseWithSuccess($this->service->getAll());
    }


    /**
     * 更新分类
     *
     * @param Request $request
     * @return mixed
     */
    public function save(Request $request)
    {
        return $this->service->save($request->post()) ?
            $this->responseWithSuccess() : $this->responseWithError();
    }


    /**
     * 删除分类
     *
     * @param Request $request
     * @return mixed
     */
    public function delete(Request $request)
    {
        return $this->service->delete($request->post('id', 0)) ?
            $this->responseWithSuccess() : $this->responseWithError();
    }

}
